/*    */ package dao.Impl;

/*    */
/*    */ import dao.RecruitDAO;
/*    */ import form.RecruitForm;

import java.io.UnsupportedEncodingException;
/*    */ import java.sql.Connection;
/*    */ import java.sql.PreparedStatement;
/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;

import com.mysql.jdbc.Statement;

/*    */ import util.JDBCUtil;

/*    */
/*    */
/*    */ public class RecruitDAOImpl/*    */ implements RecruitDAO
/*    */ {
	Connection connection = null;
	Statement statement = null;
	ResultSet resultSet = null;
	PreparedStatement preparedStatement = null;
	PreparedStatement prepareStatement = null;

	/*    */ public boolean add(RecruitForm recruitForm) {
		/* 16 */ connection = JDBCUtil.getConnection();
		/* 17 */ preparedStatement = null;
		/* 18 */ int flag = 0;
		/* 19 */ String sql = "insert into recruit(sid,name,sex,major,qq,phone,note,type,status,ip)values(?,?,?,?,?,?,?,?,?,?)";
		/*    */
		/*    */ try {
			System.out.println("old:" + new String(recruitForm.getMajor().getBytes("ISO-8859-1"), "utf-8"));
			System.out.println("new+:" + recruitForm.getMajor());
			/* 22 */ preparedStatement = connection.prepareStatement(sql);
			/* 23 */ preparedStatement.setString(1, recruitForm.getSid());
			/* 24 */ preparedStatement.setString(2, recruitForm.getName());
			/* 25 */ preparedStatement.setString(3, recruitForm.getSex());
			/* 26 */ preparedStatement.setString(4, recruitForm.getMajor());
			/* 27 */ preparedStatement.setString(5, recruitForm.getQq());
			/* 28 */ preparedStatement.setString(6, recruitForm.getPhone());
			/* 29 */ preparedStatement.setString(7, recruitForm.getNote());
			/* 30 */ preparedStatement.setString(8, recruitForm.getType());
			/* 31 */ preparedStatement.setInt(9, 0);
			/* 32 */ preparedStatement.setString(10, recruitForm.getIp());
			/* 33 */ flag = preparedStatement.executeUpdate();
			/* 34 */ } catch (SQLException e) {
			/*    */
			/* 36 */ e.printStackTrace();
			/*    */ } catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			/*    */ try {
				/* 39 */ JDBCUtil.close(connection, preparedStatement);
				/* 40 */ } catch (Exception e) {
				/*    */
				/* 42 */ e.printStackTrace();
				/*    */ }
			/*    */ }
		/* 45 */ return (flag > 0);
		/*    */ }

	/*    */
	/*    */
	/*    */ public boolean findByIp(String ip) {
		/* 50 */ connection = JDBCUtil.getConnection();
		/* 51 */ preparedStatement = null;
		/* 52 */ resultSet = null;
		/* 53 */ String sql = "select * from recruit where ip = ?";
		/*    */
		/*    */ try {
			/* 56 */ preparedStatement = connection.prepareStatement(sql);
			/* 57 */ preparedStatement.setString(1, ip);
			/* 58 */ resultSet = preparedStatement.executeQuery();
			/* 59 */ if (resultSet.next())
				/* 60 */ return true;
			/* 61 */ } catch (SQLException e) {
			/*    */
			/* 63 */ e.printStackTrace();
			/*    */ } finally {
			/*    */ try {
				/* 66 */ JDBCUtil.close(connection, preparedStatement, resultSet);
				/* 67 */ } catch (Exception e) {
				/*    */
				/* 69 */ e.printStackTrace();
				/*    */ }
			/*    */ }
		/* 72 */ return false;
		/*    */ }
	/*    */ }

/*
 * Location:
 * /Users/frank/Desktop/iotlab/WEB-INF/classes/!/dao/Impl/RecruitDAOImpl.class
 * Java compiler version: 8 (52.0) JD-Core Version: 1.0.7
 */